// 手势层
import 'package:flutter/material.dart';
import 'package:flutter_app/pages/white_board/white_board_vm.dart';
import 'package:flutter_app/utils/paint_util.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';

class GestureLayerWiget extends StatelessWidget {
  GestureLayerWiget({
    super.key,
  });

  final WhiteBoardVM _whiteBoardVM = Get.find<WhiteBoardVM>();

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
        onScaleStart: (details) {
          _whiteBoardVM.onScaleStart(details);
        },
        onScaleUpdate: (details) {
          _whiteBoardVM.onScaleUpdate(details);
        },
        onScaleEnd: (details) {
          _whiteBoardVM.onScaleEnd(details);
        },
        child: _listenerWidget());
  }

  Widget _listenerWidget() {
    return Listener(
      behavior: HitTestBehavior.opaque,
      onPointerDown: (event) {
        final index = _whiteBoardVM.graphicsList.indexWhere(
          (element) {
            return PaintUtil.isPointInPolygon(
                event.localPosition, element.points);
          },
        );
        _whiteBoardVM.onPointerDown(event);
        print("onPointerDown-${index}");
      },
      onPointerMove: (event) {
        print("onPointerMove");
      },
      onPointerUp: (event) {
        print("onPointerUp");
      },
    );
  }
}
